package org.example.project.service.impl;

import com.alibaba.fastjson.JSONObject;
import org.example.project.entity.User;
import org.example.project.dao.UserDao;
import org.example.project.service.UserService;
import org.springframework.stereotype.Service;


import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

@Service("userService")
public class UserServiceImpl implements UserService {
    @Resource
    private UserDao userDao;

    @Override
    public List<User> queryAll() {
        return this.userDao.queryAll();
    }

    @Override
    public User queryById(int id) {
        return this.userDao.queryById(id);
    }

    @Override
    public List<User> queryByName(String name){ return this.userDao.queryByName(name); }

    @Override
    public User isRegister(String username) {
        return this.userDao.isRegister(username);
    }

    @Override
    public User toLogin(String username, String password) {
        return this.userDao.toLogin(username, password);
    }

    @Override
    public User insert(User user) {
        this.userDao.insert(user);
        return this.queryById(user.getId());
    }

    @Override
    public User update(User user) {
        this.userDao.update(user);
        return this.queryById(user.getId());
    }

    @Override
    public boolean deleteById(int id) {
        return this.userDao.deleteById(id) > 0;
    }
}
